<template>
    <div class="parent">
        <lun-bo></lun-bo>
        <div class="cont">
            <div class="sort">
                <div class="title">
                    <div class="t">精选推荐</div>
                </div>
                <div class="course">
                    <div class="card" v-for="(item,index) in randomFiveList" @click.prevent="toCourseInfo(-1,index)">
                        <el-card :body-style="{ padding: '0px' ,height: '100%'}">
                            <a class="image" href="#JavaScript;">
                                <el-image
                                    :src="item.coverUrl"
                                    fit="contain">
                                    <div slot="placeholder" class="image-slot">
                                        <i class="el-icon-picture-outline"></i>
                                    </div>
                                </el-image>
                            </a>
                            <div style="padding: 14px;">
                                <a href="#JavaScript;">{{item.courseName}}</a>
                                <div class="time">
                                    <div>{{ item.teacher.name }}</div>
                                    <div>{{ item.createTime}}</div>
                                </div>
                            </div>
                        </el-card>
                    </div>
                </div>
            </div>
            <div class="sort" v-for="(gItem,i) in this.gradesList">
                <div class="title">
                    <div class="t">{{ gItem.title }}</div>
                    <div class="i">更多 <i class="el-icon-d-arrow-right"></i></div>
                </div>
                <div class="course">
                    <div class="card" v-for="(item,j) in gItem.datas" @click.prevent="toCourseInfo(i,j)">
                        <el-card :body-style="{ padding: '0px',height: '100%'}">
                            <a class="image" href="#JavaScript;">
                                <el-image
                                    :src="item.coverUrl"
                                    fit="contain">
                                    <div slot="placeholder" class="image-slot">
                                        <i class="el-icon-picture-outline"></i>
                                    </div>
                                </el-image>
                            </a>
                            <div style="padding: 14px;">
                                <a href="#JavaScript;">{{ item.courseName }}</a>
                                <div class="time">
                                    <div>{{ item.teacher.name }}</div>
                                    <div>{{ item.createTime}}</div>
                                </div>
                            </div>
                        </el-card>
                    </div>
                </div>
            </div>
        </div>
        <el-backtop :visibility-height="height"></el-backtop>
    </div>
</template>

<script>
import LunBo from '../../components/LunBo.vue';
import myBottom from '../../components/Footer.vue';

export default {
    components: {LunBo, myBottom},
    data() {
        return {
            height: 500,
            randomFiveList:null,
            gradesList:null
        }
    },
    methods: {
        toCourseInfo(i, j) {
            let course=null;

            if (i === -1) {// 精选推荐
                course=this.randomFiveList[j];
            }else{// 年级推荐
                course=this.gradesList[i].datas[j];
            }
            if (course!=null){
                console.log("toCourseInfo()", i, j, course);
                localStorage.setItem("videoinfo", JSON.stringify(course))
                this.$router.push({name: "courseInfo"})
            }
        }
    },
    mounted() {
        this.$axios.get("/course/getallRecommend").then((res)=>{
            console.log(res);
            if (res.status ===200){
                this.randomFiveList=res.data
            }else{
                this.$message({
                    message: '网络超时',
                    type: 'error'
                });
            }
        })
        this.$axios.get("/course/getFivemes").then((res)=>{
            console.log(res)
            if (res.status === 200){
                this.gradesList=res.data
            }else{
                this.$message({
                    message: '网络超时',
                    type: 'error'
                });
            }
        })
    }
};
</script>
<style scoped>
.parent {
    width: 85%;
    margin: 0 auto;
}
.el-main {
    text-align: left;
}
.el-card{
    height: 100%;
}
.cont {
    padding: 20px 0;
}

.cont .title {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cont .title .t {
    font-size: 30px;
}

.cont .title .i {
    font-size: 20px;
}

.cont .title .i:hover {
    color: deepskyblue;
}

.cont .course {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}

.card {
    width: 250px;
    margin: 20px 0;
}

.card:hover {
    box-shadow: 2px 3px 10px #ded4d4;
}

.cont .course .card a {
    color: #000000;
    text-decoration: none;
    font-size: 20px;
}

.cont .course .card a:hover {
    color: salmon;
}

.time {
    font-size: 13px;
    color: #999;
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
}

.image {
    width: 100%;
    height: 66%;
    display: block;
}
.el-image{
    height: 100%;
}

</style>
